/*
 * @Descripttion: 
 * @Author: junhuafly
 * @Date: 2020-04-21 13:43:09
 * @LastEditors: junhuafly
 * @Email: junhuafly@163.com
 * @LastEditTime: 2020-04-21 15:16:36
 */
// components/wall/index.js
let leftHeight = 0, rightHeight = 0; //分别定义左右两边的高度
let query;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    resList:{
      type:Array,
      value:[],
      observer: function (newVal, oldVal) {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [{
      title: '1',
      url: 'http://zq.jhcms.cn/attachs/photo/201711/20171130_176CFE51B6710715B1BBBEF2F86ACB0C.jpg',
     }, {
      title: '2',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg',
     },{
      title: '3',
      url: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72',
     },{
      title: '4',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg',
     },{
      title: '5',
      url: 'http://zq.jhcms.cn/attachs/photo/201711/20171130_9E39DA252E3946BE36218D85876C4AB4.jpg',
     },{
      title: '6',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg',
     },{
      title: '7',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg'
     },{
      title: '8',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg',
     },{
      title: '9',
      url: 'http://f10.baidu.com/it/u=121654667,1482133440&fm=72'
     },{
      title: '7',
      url: 'http://img4.imgtn.bdimg.com/it/u=2748975304,2710656664&fm=26&gp=0.jpg'
     },{
      title: '8',
      url: 'http://img2.imgtn.bdimg.com/it/u=1561660534,130168102&fm=26&gp=0.jpg'
     },{
      title: '9',
      url: 'http://img3.imgtn.bdimg.com/it/u=1417732605,3777474040&fm=26&gp=0.jpg'
     },{
      title: '10',
      url: 'http://zq.jhcms.cn/attachs/photo/201711/20171130_176CFE51B6710715B1BBBEF2F86ACB0C.jpg',
     }],
     resultList:[[],[]]
  },
  ready(){
    this.isLeft();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async isLeft() {
      const { list,resList, resultList } = this.data;
      query = wx.createSelectorQuery();
      for (const item of resList) {
       leftHeight <= rightHeight ? resultList[0].push(item) : resultList[1].push(item); //判断两边高度，来觉得添加到那边
       await this.getBoxHeight(resultList[0], resultList[1]);
      }
     },
     getBoxHeight(left, right) { //获取左右两边高度
      return new Promise((resolve, reject) => {
       this.setData({ 'resultList[0]':left, 'resultList[1]':right }, () => {
        query.select('#left').boundingClientRect();
        query.select('#right').boundingClientRect();
        query.exec((res) => {
         leftHeight = res[0]&&res[0].height; //获取左边列表的高度
         rightHeight = res[1]&&res[1].height; //获取右边列表的高度
         resolve();
        });
       });
      })
     },
  }
})
